package cn.iocoder.yudao.module.project.service.deptcompletedlog;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.project.controller.admin.deptcompletedlog.vo.*;
import cn.iocoder.yudao.module.project.dal.dataobject.deptcompletedlog.DeptCompletedLogDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.project.dal.mysql.deptcompletedlog.DeptCompletedLogMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.project.enums.ErrorCodeConstants.*;

/**
 * 课室完成记录 Service 实现类
 *
 * @author 管理员
 */
@Service
@Validated
public class DeptCompletedLogServiceImpl implements DeptCompletedLogService {

    @Resource
    private DeptCompletedLogMapper deptCompletedLogMapper;

    @Override
    public Integer createDeptCompletedLog(DeptCompletedLogSaveReqVO createReqVO) {
        // 插入
        DeptCompletedLogDO deptCompletedLog = BeanUtils.toBean(createReqVO, DeptCompletedLogDO.class);
        deptCompletedLogMapper.insert(deptCompletedLog);
        // 返回
        return deptCompletedLog.getId();
    }

    @Override
    public void updateDeptCompletedLog(DeptCompletedLogSaveReqVO updateReqVO) {
        // 校验存在
        validateDeptCompletedLogExists(updateReqVO.getId());
        // 更新
        DeptCompletedLogDO updateObj = BeanUtils.toBean(updateReqVO, DeptCompletedLogDO.class);
        deptCompletedLogMapper.updateById(updateObj);
    }

    @Override
    public void deleteDeptCompletedLog(Integer id) {
        // 校验存在
        validateDeptCompletedLogExists(id);
        // 删除
        deptCompletedLogMapper.deleteById(id);
    }

    private void validateDeptCompletedLogExists(Integer id) {
        if (deptCompletedLogMapper.selectById(id) == null) {
            throw exception(DEPT_COMPLETED_LOG_NOT_EXISTS);
        }
    }

    @Override
    public DeptCompletedLogDO getDeptCompletedLog(Integer id) {
        return deptCompletedLogMapper.selectById(id);
    }

    @Override
    public PageResult<DeptCompletedLogDO> getDeptCompletedLogPage(DeptCompletedLogPageReqVO pageReqVO) {
        return deptCompletedLogMapper.selectPage(pageReqVO);
    }

}